import request from '/@/utils/request';

export namespace PlanIncompleteItemsApi {
	// 未完成项查询输入参数
	export interface IncompleteItemInput {
		page?: number;
		pageSize?: number;
		ch?: string;
		fd?: string;
		workTime?: string;
		keyword?: string;
	}

	// 未完成项输出
	export interface IncompleteItemOutput {
		id: number;
		ch: string;
		fd: string;
		className: number;
		classNameFkDisplayName: string;
		workAreaId?: number;
		team?: string;
		planStart?: string;
		planEnd?: string;
		actualStart?: string;
		actualEnd?: string;
		finishDate?: string;
		missingActualStart: boolean;
		missingActualEnd: boolean;
		remark?: string;
	}

	// 批量更新项输入
	export interface BatchUpdateItemInput {
		id: number;
		actualStart?: string;
		actualEnd?: string;
		remark?: string;
	}

	// 批量更新结果
	export interface BatchUpdateResult {
		totalCount: number;
		successCount: number;
		failedCount: number;
		errors: string[];
	}

	// 未完成项统计信息
	export interface IncompleteItemsStatistics {
		totalSegments: number;
		finishedSegments: number;
		problematicSegments: number;
		totalIncompleteItems: number;
		problematicRate: number;
		problematicSegmentsList: Array<{
			ch: string;
			fd: string;
			finishDate: string;
			incompleteCount: number;
			incompleteItems: Array<{
				className: string;
				missingStart: boolean;
				missingEnd: boolean;
				team: string;
			}>;
		}>;
	}
}

/**
 * 未完成项管理API
 */
export const usePlanIncompleteItemsApi = () => ({
	/**
	 * 获取未完成项统计信息
	 * @param workTime 工作月份
	 */
	getIncompleteItemsStatistics: (workTime?: string) => {
		return request({
			url: '/api/planStatus/getIncompleteItemsStatistics',
			method: 'get',
			params: { workTime: workTime || '' },
		});
	},

	/**
	 * 获取已完成分段的未完成项清单
	 * @param input 查询参数
	 */
	getFinishedSegmentIncompleteItems: (input: PlanIncompleteItemsApi.IncompleteItemInput) => {
		return request({
			url: '/api/PlanStatus/GetFinishedSegmentIncompleteItems',
			method: 'post',
			data: input,
		});
	},

	/**
	 * 批量更新未完成项的实际时间
	 * @param items 批量更新项列表
	 */
	batchUpdateIncompleteItems: (items: PlanIncompleteItemsApi.BatchUpdateItemInput[]) => {
		return request({
			url: '/api/PlanStatus/BatchUpdateIncompleteItems',
			method: 'post',
			data: items,
		});
	},
});
